package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 陶肖寅
 * @version V1.0
 * @Package com.lagou.edu.controller
 * @date 2020-02-02 16:23
 * @Copyright © 2020-2021 城云科技(中国)有限公司
 */
@Controller
@RequestMapping("/resumes")
public class ResumeController {

    @Autowired
    ResumeService resumeService;
    @GetMapping("/addForm")
    public String addForm() throws Exception {
        return "resume/add";
    }
    @GetMapping("/editForm")
    public String editForm(Model model,Long id) throws Exception {

        Resume resume = resumeService.getResumeById(id);
        model.addAttribute("resume",resume);
        return "resume/edit";
    }
    @GetMapping("")
    public String list(Model model) throws Exception {

       List<Resume> resumes = resumeService.queryResumeList();
        model.addAttribute("resumes",resumes);
        return "resume/list";
    }
    @PostMapping("")
    public String add(Model model,Resume resume) throws Exception {
        resumeService.saveResume(resume);
        return list(model);
    }
    @PutMapping("")
    public String edit(Model model,Resume resume) throws Exception {
        resumeService.saveResume(resume);
        return list(model);
    }
    @DeleteMapping("/{id}")
    public String delete(Model model, @PathVariable("id") Long id) throws Exception {
        resumeService.deleteResume(id);
        return list(model);
    }
}
